package com.tuanbiao.presenter.auth;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.OnLifecycleEvent;

import com.hzjq.data.minbao.entity.AuthEntity;
import com.tuanbiao.base.mvp.BasePresenter;
import com.tuanbiao.controllers.AuthController;

/**
 * @author abiao
 * @since 2022/4/25 15:55
 */
public class AuthListPresenter extends BasePresenter<AuthController.Model, AuthController.ListView> implements AuthController.ListPresenter {
    private int mPageIndex = 1;

    public AuthListPresenter(AuthController.Model model, AuthController.ListView rootView) {
        super(model, rootView);
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    public void init() {
        refresh();
    }

    @Override
    public void refresh() {
        mPageIndex = 1;
        mModel.queryAuth(mPageIndex, entities -> mRootView.setItems(entities));

    }

    @Override
    public void loadMore() {
        mPageIndex++;
        mModel.queryAuth(mPageIndex, entities -> mRootView.addItems(entities));
    }

    @Override
    public void deleteAuth(AuthEntity entity) {
        mModel.deleteAuth(entity, unused -> {
            mRootView.showMessage("删除成功");
            refresh();
        });
    }
}
